package com.nlscan.qdkit.ui.publico.util;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.view.OrientationEventListener;

public class OrientationEventListenerImp extends OrientationEventListener {

    private final Activity mActivity;

    public OrientationEventListenerImp(Activity context) {
        super(context);
        mActivity = context;
    }


    @Override
    public void onOrientationChanged(int orientation) {
        //判null
        if (mActivity == null || mActivity.isFinishing()) {
            return;
        }

        if (orientation > 350 || orientation < 10) {
            //0度，用户竖直拿着手机
            if (mActivity.getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
                mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
            }
        }
    }
}
